package cn.sunline.dreamvalue.controller;

import cn.sunline.adp.infrastructure.api.FlowTranCaller;
import cn.sunline.dreamvalue.constant.CommonResult;
import cn.sunline.dreamvalue.dto.*;
import cn.sunline.dreamvalue.service.DreamAcctOpenService;
import cn.sunline.dreamvalue.service.DreamValueService;
import cn.sunline.dreamvalue.utils.DreamValueNoGenerateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author 11292
 * @title: DreamValueController
 * @projectName dream-value
 * @description: 梦想值controller
 * @date 2020/5/7 15:01
 */
@RestController
public class DreamValueController {

    public static final Logger log = LoggerFactory.getLogger(DreamValueController.class);
    @Autowired
    private FlowTranCaller flowTranCaller;

    @Autowired
    private DreamValueService dreamValueService;

    @Autowired
    private DreamAcctOpenService dreamacctopenservice;

    /**
     * 　* @description: 梦想值查询
     * 　* @param [input]
     * 　* @return java.lang.Object
     * 　* @author 11292
     * 　* @date 2020/5/7 15:02
     */
    @PostMapping("/dreamValue/query")
    public CommonResult query(DreamValueQueryInDTO input) throws Exception {
        log.info("查询梦想值接口入参为：{}",input.toString());
        return dreamValueService.query(input);
    }
    /**
     　* @description: 开启梦想旅程
     　* @param [input]
     　* @return cn.sunline.dreamvalue.constant.CommonResult
     　* @author 82345
     　* @date 2020/5/8 17:39
     */
    @PostMapping("/dreamValue/open")
    public CommonResult openDreamTravel(DreamAcctOpenDTO input) throws Exception{
        return dreamacctopenservice.openDreamTravel(input);
    }

    /**
     　* @description: 查询客户梦想值流水
     　* @param [input]
     　* @return cn.sunline.dreamvalue.constant.CommonResult<cn.sunline.dreamvalue.dto.DreamValueDetailOutDTO>
     　* @author 11292
     　* @date 2020/5/7 17:01
     */
    @PostMapping("/dreamValue/detailsQuery")
    public CommonResult<DreamValueDetailOutDTO> detailsQuery(DreamValueDetailInDTO input){
        try{
            return dreamValueService.queryDetails(input);
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed();
        }
    }

    /**
     　* @description: 梦想值调减
     　* @param [input]
     　* @return cn.sunline.dreamvalue.constant.CommonResult<java.util.Map<java.lang.String,java.lang.String>>
     　* @author 11292
     　* @date 2020/5/7 17:50
     */
    @PostMapping("/dreamValue/subtract")
    public CommonResult<Map<String,String>> subtract(DreamValueSubtractInDTO input) throws Exception {
        return dreamValueService.subtract(input);
    }

    /*@Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @Value("${dreamvalue.topic.add}")
    private String topic;*/

    @Autowired
    private DreamValueNoGenerateUtil dreamValueNoGenerateUtil;
    /**
     　* @description: 模拟发送kafka消息
     　* @param [input]
     　* @return void
     　* @author 11292
     　* @date 2020/5/8 17:08
     *//*
    @PostMapping(value = "/dreamValue/sendkafka",consumes = "application/json")
    public void sendMsg(Integer msgSize){
        for(int i = 0; i < msgSize; i ++){
            DateFormat df = new SimpleDateFormat("yyyyMMdd");
            DateFormat tf = new SimpleDateFormat("HHmmss");
            DreamValueAddInDTO input = new DreamValueAddInDTO();
            Date curDate = new Date();
            String date = df.format(curDate);
            String time = df.format(curDate);
            input.setDate(date);
            input.setTime(time);
            input.setDreamValue(RandomUtils.nextInt(msgSize));
            input.setDreamValueNo(dreamValueNoGenerateUtil.generateDreamValueNo("001"));
            input.setTransNo(dreamValueNoGenerateUtil.generateDreamValueFlowNo("01"));
            input.setType("01");
            input.setTransDesc("测试"+i);
            kafkaTemplate.send(topic, JSON.toJSONString(input));
        }
    }*/


    /**
     * 调增接口
     * @param input
     * @return
     * @throws Exception
     */
    @PostMapping("/dreamValue/add")
    public CommonResult dreamValueAdd(DreamValueAddInDTO input) throws Exception {
        return dreamValueService.dreamValueAdd(input);
    }
}
